import 'package:flutter/material.dart';
import 'package:flutter_hkzf/pages/home/tab_index/index.dart';
import 'package:flutter_hkzf/widgets/page_content.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

// List<Widget> tabViewList = [
//   const PageContent(name: "首页"),
//   const PageContent(name: "搜索"),
//   const PageContent(name: "资讯"),
//   const PageContent(name: "我的"),
// ];

List<Widget> tabViewList = [
  TabIndex(),
  const PageContent(name: "搜索"),
  const PageContent(name: "资讯"),
  const PageContent(name: "我的"),
];

// 底部导航item列表
List<BottomNavigationBarItem> barItemList = [
  const BottomNavigationBarItem(label: '首页', icon: Icon(Icons.home)),
  const BottomNavigationBarItem(label: '搜索', icon: Icon(Icons.search)),
  const BottomNavigationBarItem(label: '资讯', icon: Icon(Icons.info)),
  const BottomNavigationBarItem(label: '我的', icon: Icon(Icons.account_circle)),
];

class _HomePageState extends State<HomePage> {
  int _selectedIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: tabViewList[_selectedIndex],
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        items: barItemList,
        currentIndex: _selectedIndex,
        selectedItemColor: Colors.teal,
        onTap: _onItemTapped,
      ),
    );
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }
}
